<?php
namespace Admin\Controller;
use Think\Page;

use Think\Controller;
class LoginController extends Controller{
	public function login(){
		
		$this->display();
	}
	public function checkuser(){
		$username = I('username');
		$temp = M('user')->where(array('username'=>$username))->find();
		if(!empty($temp)){
			$this->ajaxReturn(1,'json');
		}
		else{
			$this->ajaxReturn(0,'json');
		}
	}
	public function checkpwd(){
		$username = I('username');
		$password = M('user')->where(array('username'=>$username))->getField('password');
		if($password==md5(I('password'))){
			$this->ajaxReturn(1,'json');
		}
		else{
			$this->ajaxReturn(0,'json');
		}
	}
	public function checkcode(){
		$util = A('Util');
	    if($util->check_verify(I('code'))){
	    	$this->ajaxReturn(1,'json');
	    }
	    else{
	    	$this->ajaxReturn(0,'json');
	    }
	}
	public function checklogin(){
		$db =	 M('user');
		$user =  $db->where(array('username'=>I('username')))->find();
		if(!$user || $user['password']!=I('password','','md5')){
			$this->error("账号或者密码错误!");
		}
		session('uid',$user['id']);
		session('auth',$user);
		session('username',$user['username']);
		$this->redirect('Publish/index');
	}
	public function logout(){
		session_unset();
		session_destroy();
		$this->redirect('Home/Login/login');
	}
}